package com.iafme.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import cn.hutool.core.convert.Convert;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.iafme.dto.req.ChinaReqDTO;
import com.iafme.dto.res.ChinaResDTO;
import com.iafme.model.China;
import com.iafme.service.ChinaService;
import com.systemframework.annotation.OperateAnnotation;
import com.systemframework.common.BaseCommonInterface;
import com.systemframework.enums.BusinessType;
import com.systemframework.util.Result;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @author summer
 * @version 1.0
 * @date 2025/2/21 21:03
 */
@RestController
@RequestMapping(value = "/china")
@AllArgsConstructor
public class ChinaController implements BaseCommonInterface<ChinaReqDTO, ChinaResDTO> {

    private final ChinaService chinaService;

    @OperateAnnotation(businessType = BusinessType.INSERT,name = "国内管理-委员信息")
    @SaCheckPermission("china:standard:add")
    @Override
    public Result<String> save(@Valid ChinaReqDTO chinaReqDTO) {
        China china = Convert.convert(China.class, chinaReqDTO);
        chinaService.save(china);
        return Result.successResult();
    }

    @OperateAnnotation(businessType = BusinessType.UPDATE,name = "国内管理-委员信息")
    @SaCheckPermission("china:standard:edit")
    @Override
    public Result<String> update(@Valid ChinaReqDTO chinaReqDTO) {
        China china = Convert.convert(China.class, chinaReqDTO);
        chinaService.updateById(china);
        return Result.successResult();
    }

    @OperateAnnotation(businessType = BusinessType.DELETE,name = "国内管理-委员信息")
    @SaCheckPermission("china:standard:delete")
    @Override
    public Result<String> del(Integer id) {
        chinaService.removeById(id);
        return Result.successResult();
    }

    @Override
    public Result<Page<ChinaResDTO>> lists(ChinaReqDTO chinaReqDTO) {
        return Result.successResult(chinaService.lists(chinaReqDTO));
    }

    @Override
    public Result<ChinaResDTO> findById(Integer integer) {
        return null;
    }

    @OperateAnnotation(businessType = BusinessType.BATCHDELETE,name = "国内管理-委员信息")
    @SaCheckPermission("china:standard:delete")
    @Override
    public Result<String> batchDel(List<ChinaResDTO> list) {
        List<Integer> ids = list.stream().map(ChinaResDTO::getId).collect(Collectors.toList());
        chinaService.removeByIds(ids);
        return Result.successResult();
    }
}
